//index.js
//获取应用实例
const app = getApp();
const http = require('../../modules/HomeModule');
Page({
  data: {
    inputValue: "",
    inputHistory: [],
    isFocus: false,
    hotBook:[],
    searchValue:""
  },
  async onLoad() {
    var inpHistory = wx.getStorageSync("inputHistory");
    var inputHistory = this.data.inputHistory;
    var res=await http.getHot();
    var hotBook=res.data.result.hots;
    this.setData({
      hotBook
    })
    console.log(res)
    if (inpHistory != "") {
      inputHistory = inpHistory
    }
    this.setData({
      inputHistory
    })

  },
  inputBook(e) {
    
    this.setData({
      
      inputValue: e.detail.value
    })
  },
  getInput() {
    var inputValue = this.data.inputValue;
    var inputHistory = this.data.inputHistory;
    if (this.exist(inputHistory, inputValue)) {
      inputHistory.unshift(inputValue);
      if (inputHistory.length > 10) {
        inputHistory = inputHistory.slice(0, 10);
      }
      this.setData({
        inputHistory,
        isFocus:false,
        searchValue:""
      })
      wx.setStorageSync('inputHistory', inputHistory);
    }


  },
  exist(Arrary, value) {
    var flag = Arrary.includes(value)
    if (value.trim() == "") {
      return false;
    }
    return !flag
  },
  onFocus() {
   
    this.setData({
      isFocus: true
    })
  },
  lea63veFocus() {
    
    this.setData({
      isFocus: false
    })
  },


})